//
//  ChoosePasswordViewController.m
//  ios-test
//
//  Created by Apple -11 on 15/10/22.
//  Copyright (c) 2015年 Apple -11. All rights reserved.
//

#import "ChoosePasswordViewController.h"
#import "SetPasswordViewController.h"
@interface ChoosePasswordViewController ()

@end

@implementation ChoosePasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.setArray = [NSArray arrayWithObjects:@"清除密码",@"修改密码",nil];
    self.setArray2 = [NSArray arrayWithObjects:@"设置密码",nil];

    self.setView.tableFooterView=[[UIView alloc]init];
    
     passwordUser=[NSUserDefaults standardUserDefaults];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated{
    [self.setView reloadData];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (![[passwordUser objectForKey:@"pass"]isEqualToString:@""]) {
        return self.setArray.count;

    }else
        return self.setArray2.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    static NSString *cellStr = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
    }
    if (![[passwordUser objectForKey:@"pass"]isEqualToString:@""]) {
        NSString *menu = (NSString *)[self.setArray objectAtIndex:indexPath.row];
        
        cell.textLabel.text = menu;
        
    }else{
        NSString *menu = (NSString *)[self.setArray2 objectAtIndex:indexPath.row];
        cell.textLabel.text = menu;
    }
    
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (![[passwordUser objectForKey:@"pass"]isEqualToString:@""]) {
        if (indexPath.row==0) {
            UIAlertView *alter=nil;
            alter=[[UIAlertView alloc]initWithTitle:@"提示！！！！" message:@"是否清楚密码" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否",nil];
            [alter show];
        }else{
            SetPasswordViewController *setPassword=[[SetPasswordViewController alloc]init];
            [self presentViewController:setPassword animated:YES completion:nil];
        }

    }else{
        SetPasswordViewController *setPassword=[[SetPasswordViewController alloc]init];
        [self presentViewController:setPassword animated:YES completion:nil];

    }
    
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==0) {
        [passwordUser setObject:@"" forKey:@"pass"];
        UIAlertView *alter=nil;
        alter=[[UIAlertView alloc]initWithTitle:@"提示！！！！" message:@"清楚密码成功" delegate:nil cancelButtonTitle:@"close" otherButtonTitles:nil,nil];
        [alter show];
        [self.setView reloadData];
    }
}

-(IBAction)back:(id)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end
